/**
 * Created by dale on 2017/9/12.
 */
var addressUri={
    /**
     * 获取网页后面的参数
     * @param name
     * @returns {null}
     */
    getParam: function (name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
};

var modalBind={
    bindClick:function () {
        window.top.xhTop.getModalCloseDom().click(function () {
            var saveBtn = window.top.xhTop.getModalConfirmDom();
            if(saveBtn.hasClass('disabled') || saveBtn.is(":hidden") ){
                modalBind.disabledClick();
            }else {
                modalBind.enableClick();
            }
            return false;
        });

    },
    disabledClick:function () {
        window.top.xhTop.closeModal();
        return false;
    },
    enableClick:function () {
        window.top.swal({
            title: '你确定要关闭吗?',
            text: '',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '保存并关闭',
            cancelButtonText: '关闭'
        }).then(function() {

            window.top.xhTop.getModalConfirmDom().click();
            window.top.xhTop.closeModal();
        }, function(dismiss) {
            // dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'
            if (dismiss === 'cancel') {
                window.top.xhTop.closeModal();
            }
        })

        return false;
    }
};


var myWindow={
    /**
     * 顶层窗口弹出,sweetalert2
     * @param _options
     * @param actFunc
     * @param disFunc
     *created by dale 2017/7/11 下午5:12
     */
    initPopUp:function (_options,actFunc,disFunc) {
        var _default={
            title: '确认删除',
            text: '你确定要删除这条记录吗?',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '确定',
            cancelButtonText: '取消',
        }
        if(!disFunc){
            disFunc=function (dismiss) {
                if(dismiss=='cancel'){
                    return false;
                }
            }
        }
        var _options=$.extend({}, _default, _options);
        window.top.swal(_options).then(actFunc,disFunc);
    }

};